using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ViewOnCore.HostContract.Media;

namespace UI.Control
{
    public class TagsCloudCollection : ObservableCollection<MediaData> { }

    public partial class TagsCloud : System.Windows.Controls.UserControl
    {

        #region Variables

        public TagsCloudCollection Collection = new TagsCloudCollection();

        static private DependencyProperty FieldProperty;

        public event SelectionChangedEventHandler SelectionChanged;

        #endregion

        #region Constructor

        static TagsCloud()
        {
            FieldProperty = DependencyProperty.Register("Field",
                                                        typeof(string),
                                                        typeof(TagsCloud),
                                                        new FrameworkPropertyMetadata(""));
        }

        public TagsCloud()
        {
            InitializeComponent();

            ListCollectionView view = new ListCollectionView(Collection);

            Field = "Artist";

            // Sort alphabetically by the field
            view.SortDescriptions.Add(new SortDescription(Field, ListSortDirection.Ascending));

            // Group the list by the field, the tag cloud is based on the group name and ItemCount
            view.GroupDescriptions.Add(new PropertyGroupDescription(Field));
            lstCloud.ItemsSource = view.Groups;

            lstCloud.SelectionChanged += new SelectionChangedEventHandler(lstCloud_SelectionChanged);
        }

        #endregion

        #region Properties

        public string Field
        {
            get
            {
                return (string)base.GetValue(FieldProperty);
            }
            set
            {
                base.SetValue(FieldProperty, value);
            }
        }

        #endregion

        #region SelectionChanged

        void lstCloud_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (SelectionChanged != null)
                SelectionChanged(this, e);
        }

        #endregion

    }
}